package GUI;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.Border;

public class AlgoritmiPanel{

	WidthAlgorithmCommand widthAlgorithm;
	AdancimeCommand adancimeAlgorithm;
	AdancimeLimitataCommand adancimeLimitataAlgorithm;
	AdancimeIterativaCommand adancimeIterativaAlgorithm;
	BidirectionalCommand bidirectionalAlgorithm;
	AStarCommand aStarAlgorithm;
	HillClimbingCommand hillClimbingAlgorithm;
	JPanel panel;
	
	JPanel AlgoritmiPanelConstr(JPanel pan) {
		
		panel=pan;
		JTabbedPane pane=new JTabbedPane();
		pane.setBounds(730, 10, 250, 400);
		
		Border border = BorderFactory.createLineBorder(Color.blue);
		Border borderPane =BorderFactory.createTitledBorder(border, "Alege un Algoritm");
		pane.setBorder(borderPane);
		
		//create button for the width algorithm
		Border redline = BorderFactory.createLineBorder(Color.red);
		widthAlgorithm = new WidthAlgorithmCommand();
		widthAlgorithm.setBounds(740, 50, 180, 40);
		widthAlgorithm.setBorder(redline);
		widthAlgorithm.addActionListener(new Action());
		panel.add(widthAlgorithm);
		
		//create button for the depth algorithm
		redline = BorderFactory.createLineBorder(Color.red);
		adancimeAlgorithm = new AdancimeCommand();
		adancimeAlgorithm.setBounds(740, 100, 180, 40);
		adancimeAlgorithm.setBorder(redline);
		adancimeAlgorithm.addActionListener(new Action());
		panel.add(adancimeAlgorithm);
		
		//create button for the limited depth algorithm
		redline = BorderFactory.createLineBorder(Color.red);
		adancimeLimitataAlgorithm = new AdancimeLimitataCommand();
		adancimeLimitataAlgorithm.setBounds(740, 150, 180, 40);
		adancimeLimitataAlgorithm.setBorder(redline);
		adancimeLimitataAlgorithm.addActionListener(new Action());
		panel.add(adancimeLimitataAlgorithm);
		
		//create button for the iterative depth algorithm
		redline = BorderFactory.createLineBorder(Color.red);
		adancimeIterativaAlgorithm = new AdancimeIterativaCommand();
		adancimeIterativaAlgorithm.setBounds(740, 200, 180, 40);
		adancimeIterativaAlgorithm.setBorder(redline);
		adancimeIterativaAlgorithm.addActionListener(new Action());
		panel.add(adancimeIterativaAlgorithm);
		
		//create button for the iterative depth algorithm
		redline = BorderFactory.createLineBorder(Color.red);
		bidirectionalAlgorithm = new BidirectionalCommand();
		bidirectionalAlgorithm.setBounds(740, 250, 180, 40);
		bidirectionalAlgorithm.setBorder(redline);
		bidirectionalAlgorithm.addActionListener(new Action());
		panel.add(bidirectionalAlgorithm);
		
		//create button for the a* algorithm
		redline = BorderFactory.createLineBorder(Color.red);
		aStarAlgorithm = new AStarCommand();
		aStarAlgorithm.setBounds(740, 300, 180, 40);
		aStarAlgorithm.setBorder(redline);
		aStarAlgorithm.addActionListener(new Action());
		panel.add(aStarAlgorithm);
		
		//create button for the a* algorithm
		redline = BorderFactory.createLineBorder(Color.red);
		hillClimbingAlgorithm = new HillClimbingCommand();
		hillClimbingAlgorithm.setBounds(740, 350, 180, 40);
		hillClimbingAlgorithm.setBorder(redline);
		hillClimbingAlgorithm.addActionListener(new Action());
		panel.add(hillClimbingAlgorithm);
		
		panel.add(pane);
		return panel;
				
}
	class Action implements ActionListener
    {
		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource()==widthAlgorithm){
				widthAlgorithm.execute();
			}
			else if(e.getSource()==adancimeAlgorithm){
					adancimeAlgorithm.execute();
				}
			else if(e.getSource()==adancimeLimitataAlgorithm){
				adancimeLimitataAlgorithm.execute();
			}
			else if(e.getSource()==adancimeIterativaAlgorithm){
				adancimeIterativaAlgorithm.execute();
			}
			else if(e.getSource()==bidirectionalAlgorithm){
				bidirectionalAlgorithm.execute();
			}
			else if(e.getSource()==aStarAlgorithm){
				aStarAlgorithm.execute();
			}
			else if(e.getSource()==hillClimbingAlgorithm){
				hillClimbingAlgorithm.execute();
			}
		}
    }
}
